home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Graphics / Gallery / Source / HTMLWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  27.5 KB  |  1,041 lines

  1. #include <fstream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/utility_protos.h>
  10.  
  11. #include "GUIC_Application.hpp"
  12. #include "GUIC_OldButton.hpp"
  13. #include "GUIC_Checkbox.hpp"
  14. #include "GUIC_Cycle.hpp"
  15. #include "GUIC_Date.hpp"
  16. #include "GUIC_DirectoryExamine.hpp"
  17. #include "GUIC_Error.hpp"
  18. #include "GUIC_Event.hpp"
  19. #include "GUIC_Exceptions.hpp"
  20. #include "GUIC_File.hpp"
  21. #include "GUIC_FileString.hpp"
  22. #include "GUIC_FileExamine.hpp"
  23. #include "GUIC_Fillbar.hpp"
  24. #include "GUIC_Frame.hpp"
  25. #include "GUIC_GGFXPicture.hpp"
  26. #include "GUIC_Listview.hpp"
  27. #include "GUIC_PathString.hpp"
  28. #include "GUIC_Screen.hpp"
  29. #include "GUIC_SlidingInteger.hpp"
  30. #include "GUIC_String.hpp"
  31. #include "GUIC_StringType.hpp"
  32. #include "GUIC_System.hpp"
  33.  
  34. #include "HTMLWindow.hpp"
  35. #include "PrefsWindow.hpp"
  36.  
  37. #define COPYRIGHT    "<SMALL> index file created with 'Gallery', (c) 1997 by <A HREF=\"http://www.student.uni-kl.de/~hillenbr\" TARGET=_top>Markus Hillenbrand</A> </SMALL>"
  38.  
  39. /*********************************************************************************************************/
  40.  
  41. class ScanEntry : public GUIC_ObjectC
  42.     {
  43.     public:
  44.         ScanEntry                            (GUIC_FileExamineC *file);
  45.         ~ScanEntry                            (VOID);
  46.         LONG        pack                    (VOID);
  47.         STRPTR    getClass                (VOID);
  48.         LONG        compare                (GUIC_ObjectC &o);
  49.         VOID        print                    (VOID);
  50.         
  51.         STRPTR         fileName, fileNote, name;
  52.         LONG            fileSize;
  53.         LONG            day, month, year;
  54.         LONG            errorCode;
  55.         
  56.         ScanEntry *    parent;
  57.         GUIC_ListC     directories, files;
  58.         LONG                entries;
  59.         
  60.     protected:    
  61.         LONG    count        (VOID);
  62.         VOID    cleanUp    (VOID);
  63.     };
  64.  
  65. ScanEntry::ScanEntry                            (GUIC_FileExamineC *file)
  66. {
  67.     fileName        = 0;
  68.     GUIC_SystemC::reallocString(&fileName, file->getName());
  69.  
  70.     name            = 0;
  71.     GUIC_SystemC::reallocString(&name, file->getFilePart());
  72.     
  73.     fileSize            = file->getSize();
  74.     errorCode        = 0;
  75.     parent                = 0;
  76.     entries            = 0;
  77.     
  78.     GUIC_DateC *date = file->getDate();
  79.     if (date)
  80.         {
  81.         day         = date->getDay();
  82.         month        = date->getMonth();
  83.         year        = date->getYear();
  84.         }
  85.     
  86.     fileNote        = 0;
  87.     if (file->isDirectory())
  88.         {
  89.         STRPTR dummy    = file->getFilenote();
  90.         if (dummy) GUIC_SystemC::reallocString(&fileNote, dummy);
  91.         }
  92.     
  93. }
  94. ScanEntry::~ScanEntry                        (VOID)
  95. {
  96.     if (fileName)    delete [] fileName;
  97.     if (name)        delete [] name;
  98.     if (fileNote)        delete [] fileNote;
  99.     
  100.     while (files.length()) delete (ScanEntry *)files.remove(1);
  101.     while (directories.length()) delete (ScanEntry *)directories.remove(1);
  102. }
  103. STRPTR     ScanEntry::getClass            (VOID)
  104. {
  105.     return "ScanEntry";
  106. }
  107. VOID        ScanEntry::cleanUp                (VOID)
  108. {
  109.     
  110. }
  111. LONG        ScanEntry::compare            (GUIC_ObjectC &o)
  112. {
  113.     return Stricmp(fileName, ((ScanEntry *)&o)->fileName); // Just compare the two file names    
  114. }
  115. VOID        ScanEntry::print                    (VOID)
  116. {
  117.     cout << "[" << getClass() << "," << this << ",Name=" << fileName << "]" << endl;
  118.     files.print();
  119.     directories.print();
  120. }
  121. LONG        ScanEntry::count                (VOID)
  122. {
  123.     LONG i, len;
  124.     
  125.     entries=files.length();
  126.     
  127.     len = directories.length();
  128.     for (i=1; i<=len; i++) entries += ((ScanEntry *)directories.objectAt(i))->pack();
  129.     
  130.     return entries;
  131. }
  132. LONG        ScanEntry::pack                    (VOID)
  133. {
  134.     LONG i, len, result;
  135.     ScanEntry *entry;
  136.     
  137.     result = count();
  138.     
  139.     len = directories.length();
  140.     for (i=1; i<=len; i++) 
  141.         {
  142.         entry = (ScanEntry *)directories.objectAt(i);
  143.         if (! entry->entries)
  144.             {
  145.             directories.remove(i);
  146.             delete entry;
  147.             i--;
  148.             len--;
  149.             }
  150.         }
  151.  
  152.     return result;
  153. }
  154.  
  155. /*********************************************************************************************************/
  156.  
  157. HTMLWindowC::HTMLWindowC                            (GUIC_ApplicationC &a, GUIC_ScreenC &s, PrefsWindowC &p) : GUIC_WindowC (53,30)
  158. {
  159.     app                    = &a;
  160.     screen            = &s;
  161.     pWindow            = &p;
  162.     
  163.     ps_path            = new GUIC_PathStringC            ( 1, 1,51, 2, "RAM:");
  164.     fr_picture        = new GUIC_FrameC                    (27, 4,25,20, "Picture");
  165.     lv_message    = new GUIC_ListviewC                ( 1, 4,25,20);
  166.     gp_picture        = 0;
  167.     bt_start            = new GUIC_OldButtonC            ( 1,25, 8, 4, "_Start");
  168.     fb_status        = new GUIC_FillbarC                    (10,25,42, 4, 0);
  169.  
  170.     lv_message    -> setReadOnly(TRUE);
  171.     
  172.     add(ps_path);
  173.     add(fr_picture);
  174.     add(lv_message);
  175.     add(bt_start);
  176.     add(fb_status);
  177.  
  178.     app -> addPrefs("PathToScan", ps_path);
  179.     app -> addPrefs("HTMLWindow", this);
  180.     
  181.     setTitle("Gallery - HTML Generator");
  182.     setGuideContext("HTMLWindow");
  183.     
  184.     activate();
  185. }
  186. HTMLWindowC::~HTMLWindowC                            (VOID)
  187. {
  188.     cleanUp();
  189. }
  190.  
  191. /*********************************************************************************************************/
  192.  
  193. STRPTR    HTMLWindowC::getClass                        (VOID)
  194. {
  195.     return "HTMLWindowC";
  196. }
  197.  
  198. BOOL        HTMLWindowC::action                            (GUIC_EventC &e)
  199. {
  200.     static LONG oldPriority;
  201.     
  202.     switch (e.id)
  203.         {
  204.         case GUIC_GadgetEvent:
  205.             if (e.gadget == (GUIC_GadgetC *) bt_start)
  206.                 {
  207.                 // Set the status to 0
  208.                 fb_status->set(0);
  209.                 
  210.                 // Change the Task's priority
  211.                 if (pWindow->cb_priority->get()) oldPriority = SetTaskPri(FindTask(NULL), pWindow->si_priority->get() );
  212.                 
  213.                 try 
  214.                     {
  215.                     GUIC_DirectoryExamineC dir ( ps_path->get() );
  216.                 
  217.                     app->setBusy(TRUE);
  218.                     
  219.                     ps_path->setEnabled(FALSE);
  220.                     bt_start->set("Stop");
  221.                     lv_message->delAllItems();
  222.                     
  223.                     lv_message->addItem("Scanning directory.");
  224.                     GUIC_FileExamineC filex ( ps_path->get() );
  225.                     ScanEntry firstEntry (&filex);
  226.                     setBusy(FALSE);
  227.                     scanDirectory(dir, firstEntry);
  228.                     firstEntry.pack();
  229.                     setBusy(TRUE);
  230.                     lv_message->addItem("Directory scanned.");
  231.  
  232.                     lv_message->addItem("Creating thumbnails.");
  233.                     setBusy(FALSE);
  234.                     statusActual    = 0;
  235.                     statusTotal        = firstEntry.entries;
  236.                     createThumbnails(createHTMLDir(pWindow->ps_thumbnailPath->get(), dir.getName()), dir, firstEntry);
  237.                     firstEntry.pack();
  238.                     setBusy(TRUE);
  239.                     lv_message->addItem("Thumbnails created.");
  240.  
  241.                     lv_message->addItem("Creating HTML files.");
  242.                     setBusy(FALSE);
  243.                     statusActual    = 0;
  244.                     statusTotal        = firstEntry.entries;
  245.                     createHTMLFiles(createHTMLDir(pWindow->ps_thumbnailPath->get(), dir.getName()), dir, firstEntry);
  246.                     setBusy(TRUE);
  247.                     lv_message->addItem("HTML files created.");
  248.  
  249.                     if (pWindow->cb_thumbnailDelete->get())
  250.                         {
  251.                         lv_message->addItem("Deleting thumbnails.");
  252.                         setBusy(FALSE);
  253.                         deleteThumbnails(pWindow->ps_thumbnailPath->get(), dir.getName());
  254.                         setBusy(TRUE);
  255.                         lv_message->addItem("Thumbnails deleted.");
  256.                         }
  257.  
  258.                     lv_message->addItem("Freeing memory.");
  259.                     }
  260.                 catch (GUIC_Exception &ex)
  261.                     {
  262.                     GUIC_ErrorC err ("Error", ex.getMessage() );
  263.                     err.request(this);
  264.                     }
  265.  
  266.                 lv_message->addItem("Done.");
  267.  
  268.                 ps_path->setEnabled(TRUE);
  269.                 bt_start->set("_Start");
  270.  
  271.                 // Change the priority again
  272.                 if (pWindow->cb_priority->get()) SetTaskPri(FindTask(NULL), oldPriority );
  273.  
  274.                 app->setBusy(FALSE);
  275.                 }
  276.             return TRUE;
  277.             break;
  278.         case GUIC_OpenWindow:
  279.             return TRUE;
  280.             break;
  281.         case GUIC_CloseWindow:
  282.             screen->remove(this);
  283.             return TRUE;
  284.             break;
  285.         }
  286.     
  287.     return FALSE;
  288. }
  289.  
  290. /*********************************************************************************************************/
  291.  
  292. VOID        HTMLWindowC::scanDirectory                (GUIC_DirectoryExamineC &dir, ScanEntry &parent)
  293. {
  294.     ScanEntry *entry;
  295.     
  296.     try
  297.         {
  298.         GUIC_FileExamineC *file = dir.examineNext();
  299.         while (file)
  300.             {
  301.             if (file->isDirectory())
  302.                 {
  303.                 GUIC_DirectoryExamineC nextDir (file->getName());
  304.  
  305.                 entry = new ScanEntry(file);
  306.                 entry->parent = &parent;
  307.                 parent.directories.addSorted(entry);
  308.  
  309.                 scanDirectory(nextDir, *entry); 
  310.                 }
  311.             else
  312.                 {
  313.                 entry = new ScanEntry(file);
  314.                 entry->parent = &parent;
  315.                 parent.files.addSorted(entry);
  316.                 }
  317.             
  318.             GUIC_EventC *event = app->checkEvent();
  319.             if (event && event->id == GUIC_GadgetEvent) throw GUIC_AbortX("User Abort");
  320.             
  321.             file = dir.examineNext();
  322.             }
  323.         }
  324.     catch (GUIC_Exception &) { throw; }
  325. }
  326. VOID        HTMLWindowC::createThumbnails        (STRPTR thumbnailDir, GUIC_DirectoryExamineC &dir, ScanEntry &firstEntry)
  327. {
  328.     BOOL aborted = FALSE;
  329.     
  330.     // First, we must define the offset in the file names. 
  331.     STRPTR    dirName    = dir.getName();
  332.     LONG        offset     = strlen(dirName); if (dirName[offset-1] != ':') offset++;
  333.  
  334.     // Change the current directory to the thumbnails' directory
  335.     BPTR lock = Lock (thumbnailDir, SHARED_LOCK);
  336.     if (! lock) throw GUIC_Exception("Thumbnail directory does not exist!");
  337.     BPTR oldDir = CurrentDir(lock);
  338.     
  339.     fb_status->set(0);
  340.     
  341.     try
  342.         {
  343.         // Now we can create the thumbnails and their directories 
  344.         LONG    tWidth            = pWindow->si_thumbnailWidth->get();
  345.         LONG    tHeight        = pWindow->si_thumbnailHeight->get();
  346.         BOOL    tHide            = pWindow->cb_thumbnailHide->get();
  347.         LONG    quality        = pWindow->si_quality->get();
  348.         LONG    pWidth        = 0;
  349.         LONG    pHeight        = 0;
  350.         CHAR    filenote[64];
  351.         LONG    len, i;
  352.         
  353.         len = firstEntry.directories.length();
  354.         for (i=1; i<=len; i++)
  355.             {
  356.             ScanEntry *entry = (ScanEntry *)firstEntry.directories.objectAt(i);
  357.             createDirectory(&entry->fileName[offset]);
  358.             createThumbnails(thumbnailDir, dir, *entry);
  359.             }
  360.         
  361.         len = firstEntry.files.length();
  362.         for (i=1; i<=len; i++) 
  363.             {
  364.             ScanEntry *entry = (ScanEntry *)firstEntry.files.objectAt(i);
  365.  
  366.             fb_status->set( (100*++statusActual) / statusTotal );
  367.             // Check for user abort
  368.             GUIC_EventC *event = app->checkEvent();
  369.             if (event && event->id == GUIC_GadgetEvent) throw GUIC_AbortX();
  370.     
  371.             GUIC_FileC file (&entry->fileName[offset]);
  372.             if (file.doesExist()) continue;
  373.                 
  374.             GUIC_FileExamineC fex (entry->fileName);
  375.             if (fex.getFileType() != GUIC_PictureFile) // if  (! fex.isPicture() )
  376.                 {
  377.                 delete (ScanEntry *)firstEntry.files.remove(i);
  378.                 i--;
  379.                 len--;
  380.                 continue;
  381.                 }
  382.  
  383.             try
  384.                 {
  385.                 // remove the old picture from the window
  386.                 if (gp_picture) { remove(gp_picture); delete gp_picture; }
  387.     
  388.                 // load the new one
  389.                 gp_picture    = new GUIC_GGFXPictureC(28,6,23,17,entry->fileName);
  390.                 pWidth        = gp_picture->getWidth();
  391.                 pHeight        = gp_picture->getHeight();
  392.                 gp_picture    -> setScaled(TRUE);
  393.                 gp_picture    -> setCentered(TRUE);
  394.     
  395.                 // show the new one
  396.                 add(gp_picture);
  397.                 
  398.                 // scale and save the thumbnail
  399.                 gp_picture->scaleToBox(tWidth, tHeight);
  400.                 gp_picture->saveJPEG(&entry->fileName[offset], quality);
  401.                 
  402.                 // set filenote and hide flag
  403.                 GUIC_FileExamineC file (&entry->fileName[offset]);
  404.                 if (tHide) file.setHidden(TRUE);
  405.                 sprintf(filenote, "%ld x %ld", pWidth, pHeight);
  406.                 file.setFilenote(filenote);
  407.                 }
  408.             catch (GUIC_Exception &ex)
  409.                 {
  410.                 if (gp_picture) 
  411.                     {
  412.                     entry->errorCode = gp_picture->getErrorCode();
  413.                     delete gp_picture; gp_picture=0;
  414.                     }
  415.                 CHAR text [256];
  416.                 sprintf(text, "ERROR: %s", file.getFilePart());
  417.                 lv_message->addItem(text);
  418.                 }
  419.             }    
  420.         }
  421.     catch (GUIC_AbortX)
  422.         {
  423.         aborted = TRUE;
  424.         }
  425.     catch (GUIC_Exception &ex)
  426.         {
  427.         GUIC_ErrorC err ("Error", ex.getMessage() );
  428.         err.request(this);
  429.         }
  430.     
  431.     // Change the directory        
  432.     CurrentDir(oldDir);
  433.     UnLock(lock);
  434.  
  435.     if (aborted) throw GUIC_AbortX("User Abort");
  436. }
  437.  
  438. VOID        HTMLWindowC::createHTMLFiles            (STRPTR thumbnailDir, GUIC_DirectoryExamineC &dir, ScanEntry &firstEntry)
  439. {
  440.     BOOL        aborted        = FALSE;
  441.  
  442.     // Change the current directory to the thumbnails' directory
  443.     BPTR lock = Lock (thumbnailDir, SHARED_LOCK);
  444.     if (! lock) throw GUIC_Exception("HTML directory does not exist!");
  445.     BPTR oldDir = CurrentDir(lock);
  446.  
  447.     // First, we must define the offset in the file names. 
  448.     STRPTR    dirName    = dir.getName();
  449.     LONG        offset     = strlen(dirName); if (dirName[offset-1] != ':') offset++;
  450.         
  451.     fb_status->set(0);
  452.     
  453.     try
  454.         {
  455.         createHTMLFiles2(thumbnailDir, offset, firstEntry);
  456.         }
  457.     catch (GUIC_AbortX)
  458.         {
  459.         aborted = TRUE;
  460.         }
  461.     catch (GUIC_Exception &ex)
  462.         {
  463.         GUIC_ErrorC err ("Error", ex.getMessage() );
  464.         err.request(this);
  465.         }
  466.  
  467.     // Change back to the program's directory
  468.     CurrentDir(oldDir);
  469.     UnLock(lock);
  470.     
  471.     if (aborted) throw GUIC_AbortX("User Abort");
  472. }
  473. VOID        HTMLWindowC::createHTMLFiles2        (STRPTR thumbnailDir, LONG offset, ScanEntry &firstEntry)
  474. {
  475.     LONG        directories    = firstEntry.directories.length();
  476.     LONG        files            = firstEntry.files.length();
  477.     STRPTR    dummy        = 0;
  478.     
  479.     ScanEntry *    entry;
  480.     STRPTR            dirname, title;
  481.     LONG                i;
  482.     
  483.     dirname     = firstEntry.parent ? &firstEntry.fileName[offset] : "";
  484.     title         = firstEntry.fileNote;
  485.     if (! title || title[0]==0) title = firstEntry.name;
  486.     
  487.     // Set some useful variables
  488.     BOOL        frames                    = pWindow->cb_frames->get();
  489.     STRPTR    baseName                = pWindow->st_filename->get();
  490.     STRPTR    suffix                        = pWindow->cy_suffix->getActive() == 1 ? ".html" : ".htm";
  491.     LONG        menuframeWidth    = pWindow->si_frameWidth->get();
  492.     LONG     linesInTable                = pWindow->si_tableLines->get();
  493.     LONG        columnsInTable        = pWindow->si_tableColumns->get();
  494.     BOOL        showDimensions    = pWindow->cb_showDimensions->get();
  495.     BOOL        showSize                = pWindow->cb_showSize->get();
  496.     BOOL        showDate                = pWindow->cb_showDate->get();
  497.     LONG        tableBorderSize        = pWindow->si_tableBorderSize->get();
  498.     STRPTR    pattern1                    = pWindow->fs_pattern1->get();
  499.     STRPTR    pattern2                    = pWindow->fs_pattern2->get();
  500.     STRPTR    sound1                    = pWindow->fs_sound1->get();
  501.     STRPTR    sound2                    = pWindow->fs_sound2->get();
  502.     STRPTR    color1                        = pWindow->st_tableColor1->get(); if (color1) color1 = &color1[2];
  503.     STRPTR    color2                        = pWindow->st_tableColor2->get(); if (color2) color2 = &color2[2];
  504.     STRPTR    upImage                    = pWindow->fs_up->get();                
  505.     STRPTR    leftImage                = pWindow->fs_left->get();                
  506.     STRPTR    rightImage                = pWindow->fs_right->get();            
  507.     
  508.     if (!Stricmp(pattern1, "")) pattern1=0;
  509.     if (!Stricmp(pattern2, "")) pattern2=0;
  510.     
  511.     if (!Stricmp(sound1, "")) sound1=0;
  512.     if (!Stricmp(sound2, "")) sound2=0;
  513.  
  514.     if (!Stricmp(upImage, "")) upImage=0;
  515.     if (!Stricmp(leftImage, "")) leftImage=0;
  516.     if (!Stricmp(rightImage, "")) rightImage=0;
  517.  
  518.     if (files)
  519.         {
  520.         // find out the dimensions and the name of the gallery
  521.         ldiv_t d = ldiv (files, columnsInTable );
  522.         LONG lines = d.quot;
  523.         if (d.rem) lines++;
  524.  
  525.         d = ldiv (lines, linesInTable);
  526.         LONG galleries = d.quot;
  527.         if (d.rem) galleries++;
  528.  
  529.         // Create the Frames if neccessary
  530.         if (frames)
  531.             {
  532.             // Write the frameset file
  533.             GUIC_SystemC::reallocString(&dummy, baseName, suffix);
  534.             GUIC_FileC gallery(dirname, dummy, GUIC_Write);
  535.  
  536.             gallery.write("<HTML>\n\n  <TITLE>Gallery '");
  537.             gallery.write(title);
  538.             gallery.write("'</TITLE>\n\n  <FRAMESET COLS=");
  539.             gallery.write(menuframeWidth);
  540.             gallery.write(",*>\n    <FRAME NAME=F1 SRC=\"");
  541.             gallery.write(baseName);
  542.             gallery.write("0"); 
  543.             gallery.write(suffix); 
  544.             gallery.write("\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>\n    <FRAME NAME=F2 SRC=\"");
  545.             gallery.write(baseName);
  546.             gallery.write("1"); 
  547.             gallery.write(suffix); 
  548.             gallery.write("\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>\n  </FRAMESET>\n\n</HTML>\n");
  549.  
  550.             // now create the overview over the galleries
  551.             GUIC_SystemC::reallocString(&dummy, baseName, "0", suffix);
  552.             GUIC_FileC overview (dirname, dummy, GUIC_Write);
  553.  
  554.             overview.write("<HTML>\n\n<BODY");
  555.             if (pattern1)
  556.                 {
  557.                 overview.write(" BACKGROUND=\"");
  558.                 overview.write(makeURL(pattern1, thumbnailDir, dirname) );
  559.                 overview.write("\"");
  560.                 }
  561.             overview.write(">\n\n");
  562.             if (sound1)
  563.                 {
  564.                 overview.write(" <BGSOUND SRC=\"");
  565.                 overview.write(makeURL(sound1, thumbnailDir, dirname) );
  566.                 overview.write("\">\n");
  567.                 }
  568.             overview.write("  <H2 ALIGN=Center> Gallery </H2><BR>\n\n  <UL>\n");
  569.             
  570.             for (i=1; i<=galleries; i++)
  571.                 {
  572.                 overview.write("    <LI><A HREF=\"");
  573.                 overview.write(baseName);
  574.                 overview.write(i);
  575.                 overview.write(suffix); 
  576.                 overview.write("\" TARGET=F2>Part ");
  577.                 overview.write(i);
  578.                 overview.write("</A> <BR>\n");
  579.                 }
  580.             overview.write("  </UL>\n\n  <BR><BR>\n\n");
  581.             
  582.             if (directories)
  583.                 {
  584.                 overview.write("  <H2 ALIGN=Center> More Galleries </H2><BR>\n\n  <UL>\n");
  585.                 for (i=1; i<=directories; i++)
  586.                     {
  587.                     entry = (ScanEntry *)firstEntry.directories.objectAt(i);
  588.                     overview.write("    <LI><A HREF=\"");
  589.                     overview.write(entry->name);
  590.                     overview.write("/");
  591.                     overview.write(baseName);
  592.                     overview.write(suffix);
  593.                     overview.write("\" TARGET=_top>");
  594.                     overview.write(entry->name);
  595.                     overview.write("</A> <BR>\n");        
  596.                     }
  597.                 overview.write("  </UL>\n\n  <BR><BR>\n\n");
  598.                 }
  599.                 
  600.             overview.write("  <CENTER>\n    <A HREF=\"../");
  601.             overview.write(baseName);
  602.             overview.write(suffix); 
  603.             overview.write("\" TARGET=_top> <IMG SRC=\""); 
  604.  
  605.             if (upImage)
  606.                 {
  607.                 overview.write(makeURL(upImage, thumbnailDir, dirname));
  608.                 overview.write("\" ALT=\"[up]\" BORDER=0></A>\n");
  609.                 }
  610.             else overview.write("internal-gopher-menu\" BORDER=0> up </A>\n");
  611.  
  612.             overview.write("  </CENTER>\n\n</BODY>\n\n</HTML>\n");
  613.             }
  614.  
  615.         // Create the galleries now
  616.         LONG count = 0, number, boundary;
  617.         for (number=1; number<=galleries; number++)
  618.             {
  619.             CHAR filename[256];
  620.             sprintf(filename, "%s%ld%s", baseName, number, suffix);
  621.             GUIC_FileC indexFile(dirname, filename, GUIC_Write);
  622.  
  623.             // write head and title
  624.             indexFile.write("<HTML>\n\n<HEAD>\n  <TITLE> "); 
  625.             indexFile.write(title); 
  626.             indexFile.write(" </TITLE>\n</HEAD>\n\n<BODY");
  627.             if (pattern2)
  628.                 {
  629.                 indexFile.write(" BACKGROUND=\"");
  630.                 indexFile.write(makeURL(pattern2, thumbnailDir, dirname) );
  631.                 indexFile.write("\"");
  632.                 }
  633.             indexFile.write(">\n");
  634.             if (sound2)
  635.                 {
  636.                 indexFile.write("<BGSOUND SRC=\"");
  637.                 indexFile.write(makeURL(sound2, thumbnailDir, dirname) );
  638.                 indexFile.write("\">\n");
  639.                 }
  640.             indexFile.write("\n  <CENTER>\n\n    <H2>"); 
  641.             indexFile.write(title);
  642.             indexFile.write("</H2> (Part ");
  643.             indexFile.write(number);
  644.             indexFile.write(" of ");
  645.             indexFile.write(galleries);
  646.             indexFile.write(")<BR>\n\n    <HR>\n\n    <TABLE BORDER=");
  647.             indexFile.write(tableBorderSize);
  648.             indexFile.write(" CELLSPACING=4 CELLPADDING=4>\n");
  649.  
  650.             boundary = count + columnsInTable*linesInTable;
  651.             if (boundary>files) boundary = files;
  652.  
  653.             for (i=count; i<boundary; i++)
  654.                 {
  655.                 entry = (ScanEntry *)firstEntry.files.objectAt(i+1);
  656.  
  657.                 fb_status->set( (100*++statusActual) / statusTotal );
  658.                 // Check for user abort
  659.                 GUIC_EventC *event = app->checkEvent();
  660.                 if (event && event->id == GUIC_GadgetEvent) throw GUIC_AbortX();
  661.  
  662.                 // Check if there are enough entries per line in the table
  663.                 if (count++ % columnsInTable == 0) indexFile.write("      <TR>\n");
  664.     
  665.                 // write the picture data
  666.                 indexFile.write("        <TD BGCOLOR=\"777777\"> <CENTER>");
  667.                 indexFile.write("<A HREF=\"");
  668.                 indexFile.write(makeURL(entry->fileName, thumbnailDir, dirname ) );
  669.                 indexFile.write("\"> <IMG SRC=\"");
  670.                 indexFile.write(entry->name);
  671.                 indexFile.write("\" ALT=[Thumbnail] BORDER=0> <BR>");
  672.                 indexFile.write(entry->name);
  673.                 indexFile.write(" </A>");
  674.                 
  675.                 if (showDimensions)
  676.                     {
  677.                     try
  678.                         {
  679.                         indexFile.write("<BR>");
  680.                         GUIC_FileExamineC f (&entry->fileName[offset]);
  681.                         indexFile.write(f.getFilenote());
  682.                         }
  683.                     catch (GUIC_Exception &e) {}
  684.                     }
  685.                     
  686.                 if (showDate)
  687.                     {
  688.                     indexFile.write("<BR>");
  689.                     indexFile.write(entry->day);
  690.                     indexFile.write(".");
  691.                     indexFile.write(entry->month);
  692.                     indexFile.write(".");
  693.                     indexFile.write(entry->year);
  694.                     }
  695.                     
  696.                 if (showSize)
  697.                     {
  698.                     indexFile.write("<BR> Size: ");
  699.                     indexFile.write(entry->fileSize);
  700.                     }
  701.                                     
  702.                 indexFile.write(" </TD>\n");
  703.                 }
  704.     
  705.             indexFile.write("    </TABLE>\n\n");
  706.  
  707.             if (! frames && galleries>1) // then create jump points
  708.                 {
  709.                 indexFile.write("    <BR>\n\n");
  710.     
  711.                 if (number > 1) 
  712.                     {
  713.                     indexFile.write("    <A HREF=\"");
  714.                     indexFile.write(baseName);
  715.                     indexFile.write(number-1);
  716.                     indexFile.write(suffix);
  717.                     indexFile.write("\">");
  718.                     if (leftImage)
  719.                         {
  720.                         indexFile.write(" <IMG SRC=\"");
  721.                         indexFile.write(makeURL(leftImage, thumbnailDir, dirname));
  722.                         indexFile.write("\" ALT=\"[prev]\" BORDER=0></A>\n");
  723.                         } 
  724.                     else indexFile.write("[prev] </A>\n");
  725.                     }
  726.                 else if (leftImage)
  727.                     {
  728.                     indexFile.write("    <IMG SRC=\"");
  729.                     indexFile.write(makeURL(leftImage, thumbnailDir, dirname));
  730.                     indexFile.write("\" ALT=\"[prev]\" BORDER=0>\n");
  731.                     }
  732.                 else indexFile.write("    [prev]  \n");
  733.     
  734.                 for (LONG gal=1; gal<=galleries; gal++)
  735.                     {
  736.                     if (number != gal)
  737.                         {
  738.                         indexFile.write("    <A HREF=\"");
  739.                         indexFile.write(baseName);
  740.                         indexFile.write(gal);
  741.                         indexFile.write(suffix);
  742.                         indexFile.write("\">");
  743.                         indexFile.write(gal);
  744.                         indexFile.write("</A> \n");
  745.                         }
  746.                     else 
  747.                         {
  748.                         indexFile.write("    ");
  749.                         indexFile.write(gal);
  750.                         indexFile.write(" \n");
  751.                         }
  752.                     }
  753.                 
  754.                 if (number < galleries) 
  755.                     {
  756.                     indexFile.write("    <A HREF=\"");
  757.                     indexFile.write(baseName);
  758.                     indexFile.write(number+1);
  759.                     indexFile.write(suffix); 
  760.                     indexFile.write("\">");
  761.                     if (rightImage)
  762.                         {
  763.                         indexFile.write(" <IMG SRC=\"");
  764.                         indexFile.write(makeURL(rightImage, thumbnailDir, dirname));
  765.                         indexFile.write("\" ALT=\"[next]\" BORDER=0></A>\n");
  766.                         } 
  767.                     else indexFile.write(" [next]</A>\n");
  768.                     }
  769.                 else if (rightImage)
  770.                     {
  771.                     indexFile.write("    <IMG SRC=\"");
  772.                     indexFile.write(makeURL(rightImage, thumbnailDir, dirname));
  773.                     indexFile.write("\" ALT=\"[next]\" BORDER=0>\n");
  774.                     }
  775.                 else indexFile.write("    [next]\n");
  776.                 
  777.                 indexFile.write("    <BR>\n    <A HREF=\"../");
  778.                 indexFile.write(baseName);
  779.                 indexFile.write(suffix); 
  780.                 indexFile.write("\"> <IMG SRC=\""); 
  781.  
  782.                 if (upImage)
  783.                     {
  784.                     indexFile.write(makeURL(upImage, thumbnailDir, dirname));
  785.                     indexFile.write("\" ALT=\"[up]\" BORDER=0></A>\n\n");
  786.                     }
  787.                 else  indexFile.write("internal-gopher-menu\" BORDER=0> up </A>\n\n");
  788.                 }
  789.     
  790.             indexFile.write("    <HR>\n\n    ");
  791.             indexFile.write(COPYRIGHT);
  792.             indexFile.write("\n\n  </CENTER>\n\n</BODY>\n\n</HTML>\n");
  793.             }
  794.         }
  795.     else
  796.         {
  797.         // Create the directories
  798.         GUIC_SystemC::reallocString(&dummy, baseName, suffix);
  799.         GUIC_FileC indexFile(dirname, dummy, GUIC_Write);
  800.         
  801.         indexFile.write("<HTML>\n\n<HEAD>\n  <TITLE> "); 
  802.         indexFile.write(title); 
  803.         indexFile.write(" </TITLE>\n</HEAD>\n\n<BODY");
  804.         if (pattern1)
  805.             {
  806.             indexFile.write(" BACKGROUND=\"");
  807.             indexFile.write( makeURL(pattern1, thumbnailDir, dirname) );
  808.             indexFile.write("\"");
  809.             }
  810.         indexFile.write(">\n");
  811.         if (sound1)
  812.             {
  813.             indexFile.write("<BGSOUND SRC=\"");
  814.             indexFile.write( makeURL(sound1, thumbnailDir, dirname) );
  815.             indexFile.write("\">\n");
  816.             }
  817.         indexFile.write("\n  <CENTER>\n\n  <H1>"); 
  818.         indexFile.write(title); 
  819.         indexFile.write("</H1>\n\n  <HR><BR><BR>\n\n");
  820.  
  821.         indexFile.write("  <TABLE BORDER=");
  822.         indexFile.write(tableBorderSize);
  823.         indexFile.write(" CELLSPACING=4 CELLPADDING=4>\n");
  824.         indexFile.write("    <TR> <TH BGCOLOR=\""); 
  825.         indexFile.write(color1); 
  826.         indexFile.write("\"> <CENTER> <H3> Gallery Name </H3> </TH> <TH BGCOLOR=\""); 
  827.         indexFile.write(color1); 
  828.         indexFile.writeLn("\"> <CENTER> <H3> Entries </H3> </TH> </TR>");
  829.  
  830.         for (i=1; i<=directories; i++)
  831.             {
  832.             entry = (ScanEntry *)firstEntry.directories.objectAt(i);
  833.             
  834.             STRPTR filenote    = entry->fileNote;
  835.             if (! filenote || ! filenote[0]) filenote=entry->name;
  836.  
  837.             indexFile.write("    <TR> <TD BGCOLOR=\"");
  838.             indexFile.write(color2);
  839.             indexFile.write("\"> <CENTER> <A HREF=\"");
  840.             indexFile.write(entry->name);
  841.             indexFile.write("/");
  842.             indexFile.write(baseName);
  843.     
  844.             if (! frames) indexFile.write("1");
  845.         
  846.             indexFile.write(suffix);
  847.             indexFile.write("\"> ");
  848.             indexFile.write(filenote);
  849.             indexFile.write(" </A> </TD> <TD BGCOLOR=\"");
  850.             indexFile.write(color2);
  851.             indexFile.write("\"> <CENTER> ");
  852.             indexFile.write(entry->entries);
  853.             indexFile.write(" </TD> </TR>\n");
  854.             }
  855.  
  856.         indexFile.write("  </TABLE><BR>\n\n  <A HREF=\"../");
  857.         indexFile.write(baseName);
  858.         indexFile.write(suffix);
  859.         indexFile.write("\"> <IMG SRC=\""); 
  860.  
  861.         if (upImage)
  862.             {
  863.             indexFile.write(makeURL(upImage, thumbnailDir, dirname));
  864.             indexFile.write("\" ALT=\"[up]\" BORDER=0></A>\n\n");
  865.             }
  866.         else  indexFile.write("internal-gopher-menu\" BORDER=0> up </A>\n\n");
  867.  
  868.         indexFile.write("  <HR>\n  ");
  869.         indexFile.write(COPYRIGHT);
  870.         indexFile.write("\n\n</BODY>\n\n</HTML>");
  871.         }
  872.         
  873.     for (i=1; i<=directories; i++) createHTMLFiles2(thumbnailDir, offset, *(ScanEntry *)firstEntry.directories.objectAt(i));
  874. }
  875.  
  876. VOID        HTMLWindowC::deleteThumbnails        (STRPTR tDir, STRPTR pDir)
  877. {
  878.     try
  879.         {
  880.         GUIC_DirectoryExamineC direx ( createHTMLDir(tDir, pDir) );
  881.         STRPTR realname = direx.getName();
  882.         LONG offset = strlen(realname); if (realname[offset-1] != ':') offset++;
  883.         delThumbs(direx, pDir, offset);
  884.         }
  885.     catch (GUIC_Exception &) { throw; }
  886. }
  887.  
  888. VOID        HTMLWindowC::delThumbs                    (GUIC_DirectoryExamineC &tDir, STRPTR pDir, LONG offset)
  889. {
  890.     CHAR toDelete[1024];
  891.     
  892.     try
  893.         {
  894.         GUIC_FileExamineC *file = tDir.examineNext();
  895.         while (file)
  896.             {
  897.             toDelete[0]=0;
  898.             
  899.             if (file->isDirectory())
  900.                 {
  901.                 GUIC_DirectoryExamineC nextDir (file->getName());
  902.                 delThumbs(nextDir, pDir, offset);
  903.                 }
  904.             else 
  905.                 {
  906.                 CHAR dummy[1024];
  907.                 strcpy(dummy, pDir);
  908.                 AddPart(dummy, &file->getName()[offset], 1024);
  909.                 
  910.                 GUIC_FileC f (dummy);
  911.                 if (! f.doesExist())
  912.                     {
  913.                     if (file->getFileType() == GUIC_PictureFile) 
  914.                         {
  915.                         CHAR text [256];
  916.                         sprintf(text, "DELETE: %s", file->getFilePart());
  917.                         lv_message->addItem(text);
  918.                         strcpy(toDelete, file->getName());
  919.                         }
  920.                     }
  921.                 }
  922.             
  923.             GUIC_EventC *event = app->checkEvent();
  924.             if (event && event->id == GUIC_GadgetEvent) throw GUIC_AbortX("User Abort");
  925.             
  926.             file = tDir.examineNext();
  927.             
  928.             if (toDelete[0]) DeleteFile(toDelete);
  929.             }
  930.         }
  931.     catch (GUIC_Exception &) { throw; }
  932. }
  933.  
  934. /*********************************************************************************************************/
  935.  
  936. BOOL        HTMLWindowC::createDirectory            (STRPTR p)
  937. {
  938.     BPTR lock = CreateDir(p);
  939.     if (! lock) 
  940.         {
  941.         lock = Lock(p, SHARED_LOCK);
  942.         if (! lock) return FALSE;
  943.         }
  944.         
  945.     UnLock(lock);
  946.     return TRUE;
  947. }
  948. BOOL        HTMLWindowC::createDirectory            (STRPTR exists, STRPTR p)
  949. {
  950.     BPTR lock = Lock(exists, SHARED_LOCK);
  951.     if (! lock) return FALSE;
  952.     
  953.     BPTR oldDir    = CurrentDir(lock);
  954.     BPTR newDir    = CreateDir(p);
  955.     if (! newDir) newDir = Lock(p, SHARED_LOCK);
  956.     
  957.     CurrentDir(oldDir);
  958.     UnLock(lock);
  959.     
  960.     if (! newDir) return FALSE;
  961.     UnLock(newDir);
  962.     return TRUE;
  963. }
  964. BOOL        HTMLWindowC::copyFile                        (GUIC_FileC &file, STRPTR dir1, STRPTR dir2, STRPTR name)
  965. {
  966.     LONG len = strlen(dir1) + strlen(dir2) + strlen(name) + 10;
  967.     STRPTR newfile = new CHAR [len];
  968.     strcpy(newfile, dir1);
  969.     AddPart(newfile, dir2, len);
  970.     AddPart(newfile, name, len);
  971.     BOOL result = file.copy(newfile);
  972.     delete [] newfile;
  973.     return result;
  974. }
  975. STRPTR    HTMLWindowC::makeURL                    (STRPTR file, STRPTR dir, STRPTR dir2)
  976. {
  977.     static STRPTR result = 0;
  978.     
  979.     LONG equal = 0;
  980.     while (file[equal] && dir[equal] && file[equal] == dir[equal]) equal++;
  981.     
  982.     if (equal)
  983.         {
  984.         STRING dots=""; 
  985.         LONG pos=equal;
  986.         if (dir[equal]) 
  987.             {
  988.             dots += "../";
  989.             while (dir[++pos]) if (dir[pos] == '/') dots += "../";
  990.             }
  991.         pos=-1;
  992.         if (dir2[0])
  993.             {
  994.             dots+="../";
  995.             while (dir2[++pos]) if (dir2[pos] == '/') dots += "../";
  996.             }
  997.         GUIC_SystemC::reallocString(&result, (STRPTR) dots, &file[equal]);
  998.         }
  999.     else GUIC_SystemC::reallocString(&result, "file:///", file);
  1000.     
  1001.     return result;
  1002. }
  1003. STRPTR    HTMLWindowC::createHTMLDir            (STRPTR thumbnailDir, STRPTR scanDir)
  1004. {
  1005.     STRPTR filePart = 0;
  1006.     LONG last = strlen(scanDir) - 1;
  1007.     
  1008.     if (scanDir[last] == ':')
  1009.         {
  1010.         GUIC_SystemC::reallocString(&filePart, scanDir);
  1011.         filePart[last] = 0;
  1012.         }
  1013.     else GUIC_SystemC::reallocString(&filePart, FilePart(scanDir));
  1014.     
  1015.     static STRPTR result = 0;
  1016.     if (result) delete [] result;
  1017.     LONG len = strlen(thumbnailDir) + strlen(filePart) + 5;
  1018.     result = new CHAR [len];
  1019.     strcpy(result, thumbnailDir);
  1020.     AddPart(result, filePart, len);
  1021.     delete [] filePart;
  1022.     
  1023.     if (! createDirectory(result)) throw GUIC_Exception("Can't create thumbnail directory.");
  1024.     
  1025.     return result;
  1026. }
  1027.  
  1028. /*********************************************************************************************************/
  1029.  
  1030. VOID        HTMLWindowC::cleanUp                        (VOID)
  1031. {
  1032.     delete ps_path;
  1033.     delete fr_picture;
  1034.     delete lv_message;
  1035.     delete bt_start;
  1036.     delete fb_status;
  1037.  
  1038.     if (gp_picture) { remove(gp_picture); delete gp_picture; }
  1039. }
  1040.  
  1041.